package DBLayer;

import ModelLayer.*;
import Prototypes.DataLayer;
import Prototypes.CustomerTypeResultSetModelBinder;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DBCustomerTypeContainer extends DataLayer implements ICustomerTypeContainer
{
    private static DBCustomerTypeContainer instance;

    public DBCustomerTypeContainer()
    {
        super();
    }

    public CustomerType getCustomerType(int customerTypeID)
    {
        try
        {
            Statement getCustomerTypeStatement = dbConnection.createStatement();
            String sql = "SELECT * FROM WSCustomerType WHERE CustomerTypeID = " + customerTypeID;
            
            ResultSet results = getCustomerTypeStatement.executeQuery(sql);
            
            CustomerTypeResultSetModelBinder binder = new CustomerTypeResultSetModelBinder();
            CustomerType customerType = binder.BindModel(results);

            return customerType;
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBCustomerTypeContainer.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return null;
    }

    //Static method that gives an instance of the class.
    public static DBCustomerTypeContainer getInstance()
    {
        if (instance == null)
        {
            instance = new DBCustomerTypeContainer();
        }
        return instance;
    }
}
